﻿/*
 * @Autor: PK
 * @Date: 2021-03-31 16:29:01
 * @Description: 创建Road的工厂，只需要重写 Road CreateAgency(...) 方法根据一行DataRow生成一个Road，其余逻辑已在父类实现，道路或者车站之间的互联关系请在AbstractNetwork中实现
 */

using System;
using System.Collections.Generic;
using NLog;
using ShkSimulation.core.factory;
using ShkSimulation.core.template.agency;
using ShkSimulation.core.template.model;
using ShkSimulation.carsharing.impl.elements;

namespace ShkSimulation.carsharing.impl.create {

    public class RoadFactory : AgencyFactoryByCreateParam {
        
        public static readonly string RoadId = "Id";
        public static readonly string RoadName = "Name";
        public static readonly string RoadCapacity = "Capacity";
        public static readonly string RoadLastStationId = "LastStationId";
        public static readonly string RoadNextStationId = "NextStationId";
        public static readonly string RoadDefaultLength = "RoadLength";
        public static readonly string RoadFreeSpeed = "FreeSpeed";
        public static readonly string RoadPrice = "Price";
        public static readonly string RoadFuelCost = "FuelCost";
        
        protected static readonly Logger logger = LogManager.GetLogger(nameof(StationFactory));
        
        public RoadFactory(string resourceKey) : base(resourceKey, CreateAgency) {
        }
        
        public static Agency CreateAgency(IReadOnlyDictionary<int, Agency> createdAgencies, CreateParam createParam){
            Random random = new Random();
            Dictionary<string, object> attributes = createParam.Params;
            int uniqueId = Convert.ToInt32(attributes[RoadId]);
            BaseAgencyParams baseAgencyParams = BaseAgencyParams.Create(uniqueId, 1, random.Next());
            Road road = new Road(baseAgencyParams);
            road.Name = Convert.ToString(attributes[RoadName]);
            road.Identify = "道路";
            road.LastStationId = Convert.ToInt32(attributes[RoadLastStationId]);
            road.NextStationId = Convert.ToInt32(attributes[RoadNextStationId]);
            road.RoadLength = Convert.ToDouble(attributes[RoadDefaultLength]);
            road.Capacity = Convert.ToDouble(attributes[RoadCapacity]);
            road.FreeSpeed = Convert.ToDouble(attributes[RoadFreeSpeed]);
            road.Price = Convert.ToDouble(attributes[RoadPrice]);
            road.FuelCost = Convert.ToDouble(attributes[RoadFuelCost]);
            logger.Info("创建道路 {Name}", road.Name);
            return road;
        }

    }
}
